//
//  NSTimer+Utility.m
//  DGUtilityKit
//
//  Created by Jinxiao on 1/19/14.
//  Copyright (c) 2014 debugeek. All rights reserved.
//

#import "NSTimer+Utility.h"

@implementation NSTimer (Block)

+ (id)scheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval actionBlock:(void (^)(NSTimer *))actionBlock repeats:(BOOL)repeats
{
    return [self scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(timerDidFired:) userInfo:[actionBlock copy] repeats:repeats];
}

+ (id)timerWithTimeInterval:(NSTimeInterval)timeInterval actionBlock:(void (^)(NSTimer *))actionBlock repeats:(BOOL)repeats
{
    return [self timerWithTimeInterval:timeInterval target:self selector:@selector(timerDidFired:) userInfo:[actionBlock copy] repeats:repeats];
}

+ (void)timerDidFired:(NSTimer *)timer;
{
    if([timer userInfo])
    {
        void (^actionBlock)(NSTimer *) = (void (^)(NSTimer *))[timer userInfo];
        if(actionBlock)
        {
            actionBlock(timer);
        }
    }
}

@end
